import time
from selenium import webdriver
from selenium.webdriver.common.by import By


# clear() 清除内容
# get_attribute()  获取属性值
# is_displayed()  判断元素是否可见
# is_enabled()  判断元素是否可用


class TestCase:
    def __init__(self):
        self.driver = webdriver.Chrome()

    def clear(self):
        # 清除内容
        self.driver.get('https://www.baidu.com')
        kw = self.driver.find_element(By.ID, 'kw')
        kw.send_keys('武汉天气')

        time.sleep(3)
        kw.clear()

        time.sleep(2)
        kw.send_keys('深圳天气')

        time.sleep(2)
        kw.clear()

    def get_attribute(self):
        # 获取标签html属性值
        self.driver.get('https://www.baidu.com')
        kw = self.driver.find_element(By.ID, 'kw')
        print(kw.get_attribute('outerHTML'))
        print(kw.get_attribute('class'))
        print(kw.get_attribute('id'))
        print(kw.get_attribute('name'))

    def is_displayed(self):
        # 判断标签是否在页面中显示,显示返回Ture,不显示返回False
        self.driver.get('https://www.baidu.com')
        hid = self.driver.find_element(By.XPATH, '//*[@id="form"]/input[3]')
        print(hid.is_displayed())
        su = self.driver.find_element(By.ID, 'su')
        print(su.is_displayed())

    def is_enabled(self):
        # 判断标签是否可用,可用返回True,不可以返回False
        self.driver.get('https://sahitest.com/demo/clicks.htm')
        btn = self.driver.find_element(By.CSS_SELECTOR, 'body > form > input[type=button]:nth-child(16)')
        print(btn.is_enabled())

        btn_clear = self.driver.find_element(By.XPATH, '/html/body/form/input[1]')
        print(btn_clear.is_enabled())

    def quit(self):
        self.driver.quit()


if __name__ == '__main__':
    case = TestCase()
    # case.clear()
    # case.get_attribute()
    # case.is_displayed()
    case.is_enabled()
    case.quit()
